﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Client
{
    #region  DataBase Objects

    [DataContract, Serializable]
    public class Position
    {
        [DataMember(Name = "id")]
        public int    Id     { get; set; }

        [DataMember(Name = "salary")]
        public int    Salary { get; set; }

        [DataMember(Name = "name")]
        public string Name   { get; set; }

        public Position()
        {
            Id     = Defaults.DEFAULT_INT;
            Salary = Defaults.DEFAULT_INT;
            Name   = Defaults.DEFAULT_STR;
        }

        public Position(int id, int salary, string name)
        {
            Id     = id;
            Salary = salary;
            Name   = name;
        }
    }

    [DataContract, Serializable]
    public class BankAccount
    {
        public int Id { get; set; }
        public int Sum { get; set; }

        public BankAccount()
        {
            Id  = Defaults.DEFAULT_INT;
            Sum = Defaults.DEFAULT_INT;
        }

        public BankAccount(int id, int sum)
        {
            Id  = id;
            Sum = sum;
        }
    }

    [DataContract, Serializable]
    public class Payment
    {
        [DataMember(Name = "id")]
        public int      Id            { get; set; }

        [DataMember(Name = "employee_id")]
        public int      EmployeeId    { get; set; }

        [DataMember(Name = "bank_account_id")]
        public int      BankAccountId { get; set; }

        [DataMember(Name = "sum")]
        public int      Sum           { get; set; }

        [DataMember(Name = "payment_time")]
        public string PayTime       { get; set; }

        public Payment()
        {
            Id            = Defaults.DEFAULT_INT;
            Sum           = Defaults.DEFAULT_INT;
            BankAccountId = Defaults.DEFAULT_INT;
            EmployeeId    = Defaults.DEFAULT_INT;
            PayTime       = Defaults.DEFAULT_STR;
        }

        public Payment(int id, int bankAccountId, int sum, int employeeId, string payTime)
        {
            Id              = id;
            Sum             = sum;
            BankAccountId   = bankAccountId;
            EmployeeId      = employeeId;
            PayTime         = payTime;
        }
    }

    [DataContract, Serializable]
    public class Task
    {
        [DataMember(Name = "id")]
        public int      Id              { get; set; }

        [DataMember(Name = "name")]
        public string   Title           { get; set; }

        [DataMember(Name = "start_time")]
        public string StartTime         { get; set; }

        [DataMember(Name = "end_time")]
        public string EndTime           { get; set; }

        [DataMember(Name = "estimation")]
        public string EstimationTime    { get; set; }

        [DataMember(Name = "payment")]
        public int      Cost            { get; set; }

        [DataMember(Name = "penalty")]
        public int      Penalty         { get; set; }

        [DataMember(Name = "employee_id")]
        public int      EmployeeId      { get; set; }
        
        public Task()
        {
            Id             = Defaults.DEFAULT_INT;
            Title          = Defaults.DEFAULT_STR;
            StartTime      = Defaults.DEFAULT_STR;
            EndTime        = Defaults.DEFAULT_STR;
            EstimationTime = Defaults.DEFAULT_STR;
            Cost           = Defaults.DEFAULT_INT;
            Penalty        = Defaults.DEFAULT_INT;
            EmployeeId     = Defaults.DEFAULT_INT;
        }

        public Task(int id, string title, string startTime, string endTime, string estimationTime, int cost, int penalty, int employeeId)
        {
            Id             = id;
            Title          = title;
            StartTime      = startTime;
            EndTime        = endTime;
            EstimationTime = estimationTime;
            Cost           = cost;
            Penalty        = penalty;
            EmployeeId     = employeeId;
        }
    }

    // Changed type from DateTime to string because of wrong JSON format for datetime.
    // !!!Change it back!!!
    [DataContract, Serializable]
    public class TimeTable
    {
        public int Id           { get; set; }

        [DataMember(Name = "employee_id")]
        public int EmployeeId   { get; set; }

        [DataMember(Name = "time_in")]
        public string TimeIn  { get; set; }

        [DataMember(Name = "time_out")]
        public string TimeOut { get; set; }

        public TimeTable()
        {
            Id          = Defaults.DEFAULT_INT;
            EmployeeId  = Defaults.DEFAULT_INT;
            TimeIn      = Defaults.DEFAULT_STR;
            TimeOut     = Defaults.DEFAULT_STR;
        }
        
        public TimeTable(int id, int employeeId, string timeIn, string timeOut)
        {
            Id          = id;
            EmployeeId  = employeeId;
            TimeIn      = timeIn;
            TimeOut     = timeOut;
        }
    }

    [DataContract, Serializable]
    public class Employee
    {
        [DataMember(Name="id")]
        public int           Id             { get; set; }

        [DataMember(Name="name")]
        public string        Name           { get; set; }

        [DataMember(Name = "login")]
        public string        Login          { get; set; }

        [DataMember(Name = "password")]
        public string        Password       { get; set; }

        [DataMember(Name = "role")]
        public byte          Role           { get; set; }

        [DataMember(Name="bank_account")]
        public int           BankAccountId  { get; set; }

        [DataMember(Name = "position")]
        public int           PositionId     { get; set; }

        public Employee()
        {
            Id              = Defaults.DEFAULT_INT;
            Name            = Defaults.DEFAULT_STR;
            Login           = Defaults.DEFAULT_STR;
            Password        = Defaults.DEFAULT_STR;
            Role            = Defaults.DEFAULT_ROLE;
            BankAccountId   = Defaults.DEFAULT_INT;
            PositionId      = Defaults.DEFAULT_INT;
        }

        public Employee(int id, string name, string login, string password, byte role, int bankAccountId, int positionId)
        {
            Id              = id;
            Name            = name;
            Login           = login;
            Password        = password;
            Role            = role;
            BankAccountId   = bankAccountId;
            PositionId      = positionId;
        }
    }

    #endregion
}
